hi.
i am learning about error handling as of now and i have a simple question.
when consider this program i made to test the error messages , what error should be used for the initial if no arguments are supplied to be correct. i did find the open groups definitions and read them all and i am trying them one by one this way but i dont seem to find the one that should be correct used in this context.
thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main(int argc, char** argv)
{
int i;
/* if no argcs we get an error ? */
if( argc == 1)
{
fprintf(stderr,"%s %s\n",argv[0],strerror(EACCES));
exit(1);
}
for(i=1;i < argc; i++)
if(strcmp(argv[i],"--version") == 0)
printf(" version 0.0.1\n");
else if(strcmp(argv[i],"--error1")==0)
fprintf(stderr," EACCES:%s\n",strerror(EACCES));
else if(strcmp(argv[i],"--error2")==0)
fprintf(stderr,"EADDRINUSE:%s\n",strerror(EADDRINUSE));
else if(strcmp(argv[i],"--error3") == 0)
fprintf(stderr,"E2BIG:%s\n",strerror(E2BIG));
else if(strcmp(argv[i],"--error4")==0)
fprintf(stdout,"EADDRNOTAVAIL:%s\n",strerror(EADDRNOTAVAIL));
else if(strcmp(argv[i],"--error5")==0)
printf("EAGAIN:%s\n",strerror(EAGAIN));
return 0;
}